<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>翻转数组</title>
    <script>
        //要求：将数组['red','green','blue','pink','purple']的内容反过来存放。输出['purple','pink','blue','green',red]
        //1.声明一个新数组newArr
        //2.把就数组索引号第4个取过来(arr.length - 1);给新数组索引号第0个元素(newArr.length)
        //3.采取递减的方式 i--
        //方法1
        var arr = ['red', 'green', 'blue', 'pink', 'purple'];
        var newArr = [];
        for(var i = arr.length - 1; i >= 0; i--) {
            newArr[newArr.length] = arr[i];
        }
        console.log(newArr);
        // 方法二
        var arr = ['red', 'green', 'blue', 'pink', 'purple'];
        var newArr = [];
        for (var i = 0; i < arr.length; i++) {
            newArr[newArr.length] = arr[arr.length - i - 1];
        }
        console.log(newArr);
    </script>
</head>
<body>
    
</body>
</html>